package com.example.xn.xndemo.controller;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.example.xn.xndemo.model.CourseInfo;
import com.example.xn.xndemo.service.CourseInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("test")
public class TestController {

    @Autowired
    CourseInfoService courseInfoService;
    @Autowired
    RedisTemplate redisTemplate;

    @NacosValue(value = "${xn}",autoRefreshed = true)
    String xnTest;

    @RequestMapping("test01")
    public void test(){
        System.out.println(xnTest);
        PageHelper.startPage(2,10);
        List<CourseInfo> list = courseInfoService.selectTest();
        PageInfo<CourseInfo> pageInfo = new PageInfo<CourseInfo>(list);
    }

    @RequestMapping("redisSentinelTestSet")
    public String redisSentinelTest(){
        String key = "test"+System.currentTimeMillis();
        redisTemplate.opsForValue().set(key,
                UUID.randomUUID().toString().replaceAll("-",""));
        return key;
    }

    @RequestMapping("redisSentinelTestGet/{key}")
    public String redisSentinelTestGet(@PathVariable String key){
        return redisTemplate.opsForValue().get(key).toString();
    }
}
